
import 'dart:async';
import 'package:flutter/services.dart';
import 'models/payment_intent.dart';
import 'stripe_connection_plugin_platform_interface.dart';

class StripeConnectionPlugin  {
  var methodChannel =  MethodChannel('stripe_connection_plugin');
  Function? connectionCallBack;
  Function? onInsertCallBack;
  Function? onBatteryLevelCallBack;
  Function? onBatteryWarningCallBack;
  Function? onLogCallBack;
  Function? onCashBoxConnectionChange;
  Function? onErrorLogCallBack;
  StripeConnectionPlugin(){
    methodChannel.setMethodCallHandler((call) async {
          switch (call.method) {
            case "onBatteryWarning":
              await onBatteryWarningCallBack!(call.arguments);
              break;
            case "onBatteryLevel":
              await onBatteryLevelCallBack!(call.arguments);

              break;
            case "onInsert":
              await  onInsertCallBack!(call.arguments);
              break;
            case "onStatusChange":
             await connectionCallBack!(call.arguments);
             break;
            case "onCashBoxConnectionChange":
              await onCashBoxConnectionChange!(call.arguments);
              break;
            case "log":
               await onLogCallBack!(call.arguments);
               break;
            case "onErrorLog":
              await onErrorLogCallBack!(call.arguments);
              break;
            default:
              return null;
          }

    });
  }



  Future<void> init(String sn,String localId,String baseUrl,String errorUrl) async {
    await StripeConnectionPluginPlatform.instance.init(sn, localId,baseUrl,errorUrl);
  }

  Future<void> cashBox(String cashBoxNum) async {
    await StripeConnectionPluginPlatform.instance.cashBox(cashBoxNum);
  }

  Future<bool> openCash() async{
   return  await StripeConnectionPluginPlatform.instance.openCash();
  }




  Future<StripePaymentIntent> retrievePaymentIntent(String clientSecret) async{
    return StripeConnectionPluginPlatform.instance.retrievePaymentIntent(clientSecret);
  }

  Future<bool> cancelRetrievePaymentIntent() async {
    return StripeConnectionPluginPlatform.instance.cancelRetrievePaymentIntent();

  }

  Future<Map> processPayment() async{
    return StripeConnectionPluginPlatform.instance.processPayment();
  }

  Future<Map> cancelProcessPayment() async {
   return  StripeConnectionPluginPlatform.instance.cancelProcessPayment();
  }


  Future<void> permissionAllowed() async{
   await StripeConnectionPluginPlatform.instance.permissionAllowed();
  }

  Future<String > androidRequest() async{
    return  StripeConnectionPluginPlatform.instance.androidRequest();
  }







}
